package menu

import (
	"parking-lot-go-admin/controller"
	"parking-lot-go-admin/model/admin"

	"github.com/gin-gonic/gin"
)

func UpdateMenu(c *gin.Context) {
	requestDataStruct := struct {
		Component  string `json:"component"`
		Icon       string `json:"icon"`
		Name       string `json:"name"`
		ParentId   int    `json:"parentId"`
		Path       string `json:"path"`
		Rank       int    `json:"rank"`
		ShowLink   bool   `json:"showLink"`
		ShowParent bool   `json:"showParent"`
		Title      string `json:"title"`
		Id         int    `json:"id"`
	}{}

	c.ShouldBindJSON(&requestDataStruct)

	var adminAuthRuleStruct admin.AdminAuthRuleStruct
	if err := adminAuthRuleStruct.Update(admin.AdminAuthRuleStruct{
		ParentId:   requestDataStruct.ParentId,
		Path:       requestDataStruct.Path,
		Name:       requestDataStruct.Name,
		Component:  requestDataStruct.Component,
		Title:      requestDataStruct.Title,
		ShowParent: controller.BoolToInt(requestDataStruct.ShowParent),
		Icon:       requestDataStruct.Icon,
		Rank:       requestDataStruct.Rank,
		ShowLink:   controller.BoolToInt(requestDataStruct.ShowLink),
		Id:         requestDataStruct.Id,
	}); err != nil {
		controller.Fail(c, err.Error())
		return

	}

	controller.Success(c, "")
}
